package com.example.dell.fastshopping.views;

import android.content.Context;
import android.content.res.TypedArray;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.dell.fastshopping.R;
import com.example.dell.fastshopping.utils.DensityUtil;

/**
 * Created by ${YSH} on 2019/4/18.
 * 描述        ${TODO}
 * <p>
 * 更新者       $author$
 * 更新时间     $Data$
 * 描述         ${TODO}
 */
public class CommentItem extends RelativeLayout {
    public CommentItem(Context context) {
        super(context);
        init(context, null);
    }

    public CommentItem(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init(context, attrs);
    }

    public CommentItem(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context, attrs);
    }

    private void init(Context context, AttributeSet attrs) {
        TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.CommentItem);
        String title = ta.getString(R.styleable.CommentItem_title);
       // int rightImg = ta.getResourceId(R.styleable.CommentItem_rightImg, R.drawable.arrow_right);
        int leftImg = ta.getResourceId(R.styleable.CommentItem_leftImg, -1);
        ta.recycle();

        View inflate = LayoutInflater.from(context).inflate(R.layout.user_item, this, false);

        if (leftImg==-1){
            inflate.findViewById(R.id.leftImg).setVisibility(View.GONE);
        }else {
            ((ImageView) inflate.findViewById(R.id.leftImg)).setImageResource(leftImg);
        }
        ((TextView) inflate.findViewById(R.id.title)).setText(title);
        this.addView(inflate);
    }
}
